//
//  CZTabbar.m
//  CZOC微博01
//
//  Created by 1 on 15/11/29.
//  Copyright © 2015年 itcast. All rights reserved.
//

#import "CZTabbar.h"

@interface CZTabbar ()
@property (nonatomic,weak)UIButton *addBtn;

@end

@implementation CZTabbar

 - (id)initWithFrame:(CGRect)frame
{
    if(self=[super initWithFrame:frame])
    {
        UIButton *addBtn=[[UIButton alloc]init];
        
        [addBtn setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button"] forState:UIControlStateNormal];
        
        [addBtn setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button_highlighted"] forState:UIControlStateHighlighted];
        [addBtn setImage:[UIImage imageNamed:@"tabbar_compose_icon_add"] forState:UIControlStateNormal];
        [addBtn setImage:[UIImage imageNamed:@"tabbar_compose_icon_add_highlighted"] forState:UIControlStateHighlighted];
        addBtn.size=addBtn.currentBackgroundImage.size;
        
        [self addSubview:addBtn];
        
        self.addBtn=addBtn;
        [addBtn addTarget:self action:@selector(modelViewControll) forControlEvents:UIControlEventTouchUpInside];
      
    }
    return self;
  
}
//加号按钮的点击
- (void)modelViewControll
{
   if([self.delegate respondsToSelector:@selector(tabBarClickPushButton:)])
   {
       [self.delegate tabBarClickPushButton:self];
   }
 
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    self.addBtn.centerX=self.width*0.5;
    self.addBtn.centerY=self.height*0.5;
    
    
//    NSInteger count=self.subviews.count;
       CGFloat childWidth=self.width/5;
    NSInteger index=0;
    
    for (UIView *child in self.subviews) {
        Class class= NSClassFromString(@"UITabBarButton");
           if([child isKindOfClass:class])
           {
               child.width=childWidth;
               child.x=index*childWidth;
//               child.backgroundColor=[UIColor redColor];
               index++;
              if(index==2)
              {
                  index++;
               }
               
           }
      
        
        
    }
    
    

}

@end
